package cn.wolfcode.redis.util;

import cn.wolfcode.util.Consts;
import lombok.Getter;

/**
 * redis操作key统一管理工具类
 * 约定: 一个key 对应一枚举实例
 * 1: key的维护
 * 2: key有效性维护
 *
 */
@Getter
public enum RedisKeys {

    TOKEN_CODE("token_code",Consts.USER_INFO_TOKEN_VAI_TIME*60L),
    RANK_CODE("rank_code",Consts.USER_INFO_TOKEN_VAI_TIME*60L),

    BRUSH_PROOF("brush_proof",60L),


    //用户登录token的key的实例
    USER_TOKEN("user_token", Consts.USER_INFO_TOKEN_VAI_TIME * 60L),
    //短信验证码的key实例
    VERIFY_CODE("verify_code", Consts.VERIFY_CODE_VAI_TIME * 60L);

    private String prefix; //key的前缀
    private Long time;  //约定时间单位是秒

    private RedisKeys(String prefix, Long time){
        this.prefix  = prefix;
        this.time = time;
    }

    public String join(String... values){
        StringBuilder sb = new StringBuilder(50);
        sb.append(this.prefix);
        for (String value : values) {
            sb.append(":").append(value);
        }
        return sb.toString();
    }
}
